package com.dayuanit.space.engine;

import com.dayuanit.space.car.Car;

import java.util.HashMap;
import java.util.Map;

public class EngineFactory {

	private static final Engine forwardEngine = new ForwardEngine();
	private static final Engine backEngine = new BackEngine();
	private static final Engine leftEngine = new LeftEngine();
	private static final Engine rightEngine = new RightEngine();
	private static final Engine rollBackEngine = new RollbackEngine();

	//Map key-指令 value-引擎
	private Map<Character, Engine> enginMap = new HashMap();

//	public EngineFactory() {
//		init();
//	}

	{
		init();
	}

	static {
//		init();//error
	}

	public void init() {
		enginMap.put(Car.w_order, forwardEngine);
		enginMap.put(Car.s_order, backEngine);
		enginMap.put(Car.a_order, leftEngine);
		enginMap.put(Car.d_order, rightEngine);
		enginMap.put(Car.r_order, rollBackEngine);
	}

	public Engine create(char order) {
		return enginMap.get(order);
	}
}